package com.meng.mmlive.mvp.presenter;

import com.meng.mmlive.mvp.view.SessionView;

import java.util.List;

import io.rong.imlib.RongIMClient;
import io.rong.imlib.model.Conversation;
import io.rong.imlib.model.Message;

/**
 * Created by Administrator on 2017/5/15.
 */

public class SessionPressenter extends BasePresenterImpl<SessionView>{
    public void clearMessagesUnreadStatus(String mSessionId){
        RongIMClient.getInstance().clearMessagesUnreadStatus(
                Conversation.ConversationType.PRIVATE, mSessionId, null);
    }
    private int oldestMessageId = -1;
    private int mMessageCount = 10;
    public void loadData(String mSessionId) {
        RongIMClient.getInstance().getHistoryMessages(Conversation.ConversationType.PRIVATE,
                mSessionId,
                oldestMessageId,
                mMessageCount,
                new RongIMClient.ResultCallback<List<Message>>() {
                    @Override
                    public void onSuccess(List<Message> messages) {
                        if(messages != null && messages.size() > 0){
                            if(getView() != null ){
                                getView().showMessages(messages);
                                getView().pullLoadComplete();
                            }
                            oldestMessageId = messages.get(messages.size()-1).getMessageId();
                        }else{
                            hasMoreMessage = false;
                            if(getView() != null ){
                                getView().pullLoadComplete();
                            }
                        }
                    }

                    @Override
                    public void onError(RongIMClient.ErrorCode errorCode) {

                    }
                });
    }
    private boolean hasMoreMessage = true;
    public boolean hasMoreMessage() {
        return hasMoreMessage;
    }
}
